package model

import (
	"2301_dockers/appconfig"
	"fmt"
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
	"log"
)

var err error
var DB *gorm.DB

func Init() {
	var mysqlconfig = appconfig.AppConf.Mysql
	dsn := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8mb4&parseTime=True&loc=Local",
		mysqlconfig.User, mysqlconfig.Password, mysqlconfig.Host, mysqlconfig.Port, mysqlconfig.Database)
	DB, err = gorm.Open(mysql.Open(dsn), &gorm.Config{})
	if err != nil {
		panic("数据库链接失败")
		return
	} else {
		log.Println("数据库链接成功")
	}
	DB.AutoMigrate(&Docker{})
}
